import { _decorator, Color, color, Component, Node, Sprite } from 'cc';
import { ButtonState, PixelButton } from './PixelButton';
const { ccclass, property } = _decorator;

@ccclass('PixelButtonTest')
export class PixelButtonTest extends Component {
    protected onLoad(): void {
        this.node.on(
            PixelButton.EventStateChange,
            this.onStateChange,
            this,
        );
    }

    onStateChange(state: ButtonState, pb: PixelButton) {
        console.log('onStateChange', ButtonState[state]);

        const sprite = this.node.getComponent(Sprite)!;
        switch (state) {
            case ButtonState.NORMAL:
                sprite.color = color(255, 255, 255, 255);
                break;
            case ButtonState.HOVER:
                sprite.color = color(200, 200, 200, 255);
                break;
            case ButtonState.PRESSED:
                sprite.color = color(100, 100, 100, 255);
                break;
            case ButtonState.DISABLED:
                break;
        }
    }

    onClick(pb: PixelButton) {
        console.log('onClick');
    }
}
